<?php

require_once APP_PATH.'/Controller/BaseController.php';
require_once APP_PATH.'/Model/ArticleModel.php';
require_once APP_PATH.'/Model/CategoryModel.php';

class ArticleController extends BaseController {
	
	public function index(){
		if (!empty($_GET['catename'])){
			$map['c.bname'] = $_GET['catename'];
			$map['a.is_private'] = 0;
		}
		
		$articleModel = new ArticleModel();
		$categoryModel = new CategoryModel();
		
//		if (empty($_GET['pageid'])){
//			echo "没有页码";
//		} else {
//			echo "页码是：".$_GET['pageid'];
//		}
		
		
		/*if (isset($_REQUEST['searchValue'])){
			$searchValue = trim($_REQUEST['searchValue']);
			$map['softname'] = array('like',"%$searchValue%");
			$mapParam['searchValue'] = $searchValue;
		}*/
		
//		$count = $Article->where(@$map)->count();
//		import("@.ORG.Page"); //导入分页类
//		$p = new Page($count,8);
		
		//分页跳转的时候保证查询条件
//		foreach($mapParam as $key=>$val) {
//			$p->parameter   .=   "$key=".$val."&";		
//		}
//		if (isset($_GET['orderby'])){
//			//$orderValue = $_GET['orderby'];
//			switch ($_GET['orderby']){
//				case 'today' :
//					$orderSql = "today_down_count desc,";
//					break;
//				case 'yesterday' :
//					$orderSql = "yesterday_down_count desc,";
//					break;
//				case 'time' :
//					
//					break;
//			}
//		}
//		$articlelist  = $Article->where(@$map)->Order('create_time desc')->limit($p->firstRow.','.$p->listRows)->select();
//		var_dump($Article->getLastSql());
//		print_r($articlelist);
//		exit();
		
		$this->assign('articlelist',$articleModel->getArticleList($map));
		$this->assign("catelist",$categoryModel->getScrollData());
		$this->display('Article/articlelist.html');
	}
	
	public function read(){
		$htmlpath = $_GET['htmlpath'];
		$articleModel = new ArticleModel();
		$categoryModel = new CategoryModel();
		
		$this->assign('catelist',$categoryModel->getScrollData());
		$this->assign('article',$articleModel->getArticle($htmlpath));
		$this->display('Article/article.html');
	}
	
}